package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsService;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDto dto) {
        return wmNewsService.findAll(dto);
    }

    /*
     * @description: 文章的发布
     * @author: 椎名真白
     * @date: 2022-06-14 18:04
     * @param: dto
     * @return: com.heima.model.common.dtos.ResponseResult
     **/
    @PostMapping("/submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto dto){
        return  wmNewsService.submitNews(dto);
    }

    /*
     * @description: 获取文章详情
     * @author: 椎名真白
     * @date: 2022-06-14 21:58
     * @param: id
     * @return: com.heima.model.common.dtos.ResponseResult
     **/
    @GetMapping("one/{id}")
    public ResponseResult getOne(@PathVariable Integer id){
        return wmNewsService.getOne(id);
    }

    /*
     * @description: 根据id删除文章
     * @author: 椎名真白
     * @date: 2022-06-14 22:12
     * @param: id
     * @return: com.heima.model.common.dtos.ResponseResult
     **/
    @GetMapping("del_news/{id}")
    public ResponseResult deleteNews(@PathVariable Integer id){
        return wmNewsService.MyremoveById(id);
    }

    /*
     * @description: 文章上下架
     * @author: 椎名真白
     * @date: 2022-06-14 22:13
     * @return: com.heima.model.common.dtos.ResponseResult
     **/
    @PostMapping("down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto wmNewsDto){
        return wmNewsService.downOrUp(wmNewsDto);
    }

}